hysop.core.arrays.array module¶
- class hysop.core.arrays.array.Array(handle, backend, **kwds)[source]¶
Bases:
object
Interface of an abstract array. An array is a numpy.ndarray work-alike that stores its data and performs its computations on various devices, depending on the backend. All exposed functions should work exactly as in numpy. Arithmetic methods in Array, when available, should at least support the broadcasting of scalars.
For Fortran users, reverse the usual order of indices when accessing elements of an array. to be in line with Python semantics and the natural order of the data. The fact is that Python indexing on lists and other sequences naturally leads to an outside-to inside ordering (the first index gets the largest grouping, and the last gets the smallest element).
See https://docs.scipy.org/doc/numpy-1.10.0/reference/internals.html for more information about C versus Fortran ordering in numpy.
Numpy notation are used for axes, axe 0 is the slowest varying index and last axe is the fastest varying index. By default:
3D C-ordering is [0,1,2] which corresponds to ZYX transposition state. 3D Fortran-ordering is [2,1,0] which corresponds to XYZ transposition state.
The last axe is the memory contiguous one (X in C-ordering and Z in Fortran-ordering). This means that when taking array byte strides, in the axis order, the strides are decreasing until the last stride wich is the size of array dtype in bytes.
Build an Array instance.
- Parameters:
handle (buffer backend implementation)
backend (backend used to build this andle)
kwds (arguments for base classes.)
Notes
This should never be called directly by the user. Arrays should be constructed using array backend facilities, like zeros or empty. The parameters given here refer to a low-level method for instantiating an array.
- property T¶
Same as self.transpose(), except that self is returned if self.ndim < 2.
- any(axis=None, out=None, **kargs)[source]¶
Returns True if any of the elements of a evaluate to True.
- argmax(axis=None, out=None, **kargs)[source]¶
Return indices of the maximum values along the given axis.
- argmin(axis=None, out=None, **kargs)[source]¶
Return indices of the minimum values along the given axis of a.
- argpartition(kth, axis=-1, kind='quicksort', order=None, **kargs)[source]¶
Returns the indices that would partition this array.
- argsort(axis=-1, kind='quicksort', order=None, **kargs)[source]¶
Returns the indices that would sort this array.
- abstract as_symbolic_array(name, **kwds)[source]¶
Return a symbolic array variable that contain a reference to this array.
- abstract as_symbolic_buffer(name, **kwds)[source]¶
Return a symbolic buffer variable that contain a reference to this array.
- astype(dtype, order=SAME_ORDER(3), casting='unsafe', subok=True, copy=True, **kargs)[source]¶
Copy of the array, cast to a specified type.
- property backend¶
Return the backend corresponding to this array.
- abstract property base¶
Base object if memory is from some other object.
- byteswap(inplace=False, **kargs)[source]¶
Swap the bytes of the array elements Toggle between low-endian and big-endian data representation by returning a byteswapped array, optionally swapped in-place.
- choose(choices, out=None, mode='raise', **kargs)[source]¶
Use an index array to construct a new array from a set of choices.
- clip(min=None, max=None, out=None, **kargs)[source]¶
Return an array whose values are limited to min, max.
- compress(condition, axis=None, out=None, **kargs)[source]¶
Return selected slices of this array along given axis.
- property ctypes¶
An object to simplify the interaction of the array with the ctypes module.
- cumprod(axis=None, dtype=None, out=None, **kargs)[source]¶
Return the cumulative product of the elements along the given axis.
- cumsum(axis=None, dtype=None, out=None, **kargs)[source]¶
Return the cumulative sum of the elements along the given axis.
- abstract property data¶
Buffer object pointing to the start of the array’s data
- abstract property dtype¶
numpy.dtype representing the type stored into this buffer.
- property flags¶
Information about the memory layout of the array.
- flatten(order=SAME_ORDER(3), **kargs)[source]¶
Return a copy of the array collapsed into one dimension.
- abstract get(handle=False)[source]¶
Returns a HostArray, view or copy of this array in the host memory. Usefull for backends thats do not share physical memory with the host.
- get_order()[source]¶
Memory ordering. Determine whether the array view is written in C-contiguous order (last index varies the fastest), or FORTRAN-contiguous order in memory (first index varies the fastest). If dimension is one, default_order is returned.
- abstract get_strides()[source]¶
Tuple of ints that represents the byte step in each dimension when traversing an array.
- property handle¶
Return underlying implementation of this buffer.
- property imag¶
The imaginary part of the array.
- abstract property int_ptr¶
Return the underlying buffer pointer as an int.
- is_fortran_contiguous()[source]¶
Return true if dimension is one or if current order is F_CONTIGUOUS.
- is_hysop_contiguous()[source]¶
Return true if dimension is one or if current order corresponds to hysop default order.
- property itemsize¶
Number of bytes per element.
- logical_axes()[source]¶
Logical axes state ids, in numpy convention, as a tuple. Axe 0 is the slowest varying index, last axe is the fastest varying index. ie 3D C-ordering is [2,1,0]
3D fortran-ordering is [0,1,2]
Thoses are the axes seen as a numpy view on memory, only strides are permutated for access, Those axes are found by reverse argsorting the array strides, using a stable sorting algorithm.
- Logical permutations can be achieved through numpy-like routines present in ArrayBackend:
- and Array property:
*Array.T
See Array.physical_axes() for physical permutations of axes. See Array.axes() for overall array permutation. See https://docs.scipy.org/doc/numpy-1.10.0/reference/internals.html for more information about C versus Fortran ordering in numpy.
- mean(axis=None, dtype=None, out=None, **kargs)[source]¶
Returns the average of the array elements along given axis.
- property nbytes¶
Number of bytes in the whole buffer.
- abstract property ndim¶
Number of array dimensions.
- abstract property offset¶
Offset of array data in buffer.
- property order¶
Memory ordering. Determine whether the array view is written in C-contiguous order (last index varies the fastest), or FORTRAN-contiguous order in memory (first index varies the fastest). If dimension is one, default_order is returned.
- partition(kth, axis=-1, kind='quicksort', order=None, **kargs)[source]¶
Rearranges the elements in the array in such a way that value of the element i in kth position is in the position it would be in a sorted array.
- prod(axis=None, dtype=None, out=None, **kargs)[source]¶
Return the product of the array elements over the given axis
- ptp(axis=None, out=None, **kargs)[source]¶
Peak to peak (maximum - minimum) value along a given axis.
- property real¶
The real part of the array.
- reshape(new_shape, order=C_CONTIGUOUS(0), **kargs)[source]¶
Returns an array containing the same data with a new shape.
- round(decimals=0, out=None, **kargs)[source]¶
Return a with each element rounded to the given number of decimals.
- searchsorted(v, side='left', sorter=None, **kargs)[source]¶
Find indices where elements of v should be inserted in a to maintain order.
- abstract set_shape()[source]¶
Set the shape of this buffer. From the numpy doc: It is not always possible to change the shape of an array without copying the data. If you want an error to be raised if the data is copied, you should assign the new shape to the shape attribute of the array.
- setfield(val, dtype, offset=0)[source]¶
Put a value into a specified place in a field defined by a data-type. Place val into a’s field defined by dtype and beginning offset bytes into the field.
- setflags(write=None, align=None, uic=None)[source]¶
Set array flags WRITEABLE, ALIGNED, and UPDATEIFCOPY, respectively.
- abstract property shape¶
The real shape of this buffer.
Returns true if self may share the same physical memory as other.
- property size¶
Number of elements in the array.
- std(axis=None, dtype=None, out=None, ddof=0, **kargs)[source]¶
Returns the standard deviation of the array elements along given axis.
- abstract property strides¶
Tuple of ints that represents the byte step in each dimension when traversing an array.
- sum(axis=None, dtype=None, out=None, **kargs)[source]¶
Return the sum of the array elements over the given axis.
- swapaxes(axis1, axis2, **kargs)[source]¶
Return a view of the array with axis1 and axis2 interchanged.
- take(indices, axis=None, out=None, mode='raise', **kargs)[source]¶
Return an array formed from the elements of a at the given indices.
- tobytes(order=C_CONTIGUOUS(0))[source]¶
Construct Python bytes containing the raw data bytes in the array.
- tofile(fid, sep='', format='%s', **kargs)[source]¶
Write array to a file as text or binary (default). This is a convenience function for quick storage of array data. Information on endianness and precision is lost.
- tostring(order=SAME_ORDER(3), **kargs)[source]¶
Construct Python bytes containing the raw data bytes in the array.
- trace(offset=0, axis1=0, axis2=1, dtype=None, out=None, **kargs)[source]¶
Return the sum along diagonals of the array.